package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/21 17:14
 * @description
 */
public class Code541 {
    private StringBuilder sb = new StringBuilder();

    public String reverseStr(String s, int k) {
        if (s.length() <= k) {
            sb.append(new StringBuilder(s).reverse());
        } else if (s.length() <= 2 * k) {
            sb.append(new StringBuilder(s.substring(0, k)).reverse());
            sb.append(s.substring(k));
        } else {
            sb.append(new StringBuilder(s.substring(0, k)).reverse());
            sb.append(s, k, 2 * k);
            s = s.substring(2 * k);
            reverseStr(s, k);
        }
        return sb.toString();
    }
}
